package com.share.finance.asset.sjd.web;

import com.share.common.common.Page;
import com.share.common.common.Result;
import com.share.common.utils.DbUtil;
import com.share.finance.asset.sjd.model.vo.LogPageReq;
import com.share.finance.asset.sjd.service.IAccessLogService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.util.Map;

/**
 * <p>
 * 用户文件表  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-09-08
 */
@RestController
public class CommonController {
    @Autowired
    private DataSource dataSource;

    @Autowired
    private IAccessLogService accessLogService;

    @ApiOperation("清理删除表中的数据,保留最近的n条")
    @ResponseBody
    @RequestMapping(value = "/common/deleteLog")
    public Result deleteLog(Integer retainNum) {
        final String[] tables = {"access_log", "ast_user_file", "ast_event_info", "ast_user_info", "ast_user_bind_card"};
        Map<String, Object> reMap = DbUtil.deleteDataById(dataSource, tables, retainNum);
        return Result.success(reMap);
    }

    @ApiOperation("分页查询")
    @RequestMapping(value = "/log/pageList")
    public Result logPageList(LogPageReq req) {
        Page page = accessLogService.pageList(req);
        return Result.success(page);
    }
}
